package com.extract.runner;

import com.extract.query.DatabaseBuilder;
import com.extract.sys.entity.DatabaseSource;
import com.extract.sys.service.IDatabaseSourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: chenfenghai
 * @version: 1.0
 * @date: 2020-10-14 9:38
 */
@Slf4j
@Component
public class DatabaseSourceRunner implements ApplicationRunner {

    @Autowired
    DatabaseBuilder databaseBuilder;

    @Autowired
    IDatabaseSourceService databaseSourceService;

    @Autowired
    TaskRecordRunner taskRecordRunner;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        loadDatabaseSource();

    }

    private void loadDatabaseSource(){
        List<DatabaseSource> datasourceList = databaseSourceService.list();
        datasourceList.forEach(databaseBuilder::addDataSource);
        taskRecordRunner.startTaskRecord();
    }
}
